home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
win_q_t
/
trem.zip
/
COMM.C
< prev
next >
Wrap
Text File
|
1991-05-11
|
3KB
|
96 lines
/************************************************************************
*
* Copyright (c) 1991 Microsoft Corporation. All Rights Reserved.
*
*-----------------------------------------------------------------------
*
* Project: Windows Terminal Example
*
* Module: comm.c
*
* Author: Bryan A. Woodruff (baw)
*
*
* Remarks: Handles writing and reading from COM port.
*
* Revisions:
* 01.00.000 5/10/91 baw Wrote it
*
************************************************************************/
#include "terminal.h"
/************************************************************************
* int ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )
*
* Description:
* Reads a block from the COM port and stuffs it into
* the provided block.
*
* Comments:
* 5/10/91 baw Wrote it.
*
************************************************************************/
int ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )
{
int nLength, nError ;
LOCALHANDLE hTermInfo ;
NPTERMINFO npTermInfo ;
#ifdef DISPLAY_ERRORS
char szError[ 10 ] ;
#endif
hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
return ( FALSE ) ;
while (nError = GetCommError( npTermInfo -> nCid, NULL))
{
#ifdef DISPLAY_ERRORS
wsprintf( szError, "<CE-%d>", nError ) ;
WriteTerminalBlock( hWnd, szError, lstrlen( szError ) ) ;
#endif
}
nLength = ReadComm( npTermInfo -> nCid, lpszBlock, nMaxLength ) ;
LocalUnlock( hTermInfo ) ;
return ( nLength ) ;
} /* end of ReadCommBlock() */
/************************************************************************
* BOOL WriteCommByte( HWND hWnd, BYTE bByte )
*
* Description:
* Writes a byte to the COM port.
*
* Comments:
* 5/10/91 baw Wrote it.
*
************************************************************************/
BOOL WriteCommByte( HWND hWnd, BYTE bByte )
{
LOCALHANDLE hTermInfo ;
NPTERMINFO npTermInfo ;
hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
return ( FALSE ) ;
WriteComm( npTermInfo -> nCid, (LPSTR) &bByte, 1 ) ;
LocalUnlock( hTermInfo ) ;
return ( TRUE ) ;
} /* end of WriteCommByte() */
/************************************************************************
* End of File: comm.c
************************************************************************/